﻿Module Module10
    ' Const 參考課本 2-11 頁
    Const MIN_X = 0
    Const MAX_X = 79
    Const MIN_Y = 0
    Const MAX_Y = 23

    Sub Main()

        WriteAt(80, 25, "Hello")
        WriteAt(".NET", 10, 5)
        Console.ReadKey()

        'Dim X, Y As Integer
        'X = 10
        'Y = 20
        'Swap(X, Y)
        'Console.WriteLine("X={0} , Y={1}", X, Y)
        'Console.ReadKey()

    End Sub

    Sub Swap(ByRef A As Integer, ByRef B As Integer)
        Dim C As Integer
        C = A
        A = B
        B = C
    End Sub


    Sub WriteAt(ByVal x As Integer, ByVal y As Integer, ByVal s As String)
        ' 檢查 X 座標是否需要調整
        If x < 0 Then
            x = 0
        ElseIf (x + s.Length) > (MAX_X + 1) Then
            ' Length 為字串物件的屬性，代表字串的長度
            x = 80 - s.Length
        End If

        ' 檢查 Y 座標是否需要調整
        If y < 0 Then
            y = 0
        ElseIf y > 23 Then
            y = 23
        End If

        Console.SetCursorPosition(x, y)
        Console.Write(s)
    End Sub

    Sub WriteAt(ByVal s As String, ByVal x As Integer, ByVal y As Integer)
        WriteAt(x, y, s)
    End Sub

End Module
